package com.cymal.condition.component;


import com.cymal.condition.Condition;
import com.cymal.entity.po.subject.AbstractSubject;
import org.apache.commons.lang3.BooleanUtils;

import java.util.Collection;
import java.util.Objects;

/**
 * 否条件
 * @param <Subject>> 题目
 * @param <Req> 请求
 */
public class NotCondition<Subject extends AbstractSubject, Req> implements Condition<Subject ,Req> {


    /**
     * 题目
     */
    private final Subject subject;


    /**
     * 子条件
     */
    private final Condition<Subject, Req> child;


    /**
     * Constructor.
     * @param child 子条件
     */
    public NotCondition(Subject subject ,Condition<Subject ,Req> child) {
        if (Objects.isNull(child)) {
            throw new NullPointerException("child must not be null.");
        }
        if (Objects.isNull(subject)) {
            throw new NullPointerException("subject must not be null.");
        }
        this.subject = subject;
        this.child = child;
    }


    /**
     * 匹配结果.
     * @param subject 题目
     * @param requests 请求.
     * @return ture or false.
     */
    @Override
    public Boolean matched(Subject subject, Req... requests) {
        return BooleanUtils.isFalse(this.child.matched(subject ,requests));
    }


    @Override
    public Boolean matched(Subject subject, Collection<Req> requests) {
        return null;
    }


    /**
     * 逻辑条件没有类型
     * @return null
     */
    @Override
    public AbstractSubject.SubjectType conditionType() {
        return null;
    }

}
